#include <stddef.h>
#ifndef N2BASELIB_STRING_POOL_H_9D2202204429CCA7EE0790C38EEE17A6
#define N2BASELIB_STRING_POOL_H_9D2202204429CCA7EE0790C38EEE17A6     1

#include "n2types.h"

class N2StringPool
{
private:
    size_t          alloc_size;
    size_t          curptr;
    size_t          base;
    size_t addByteData(const char* str, size_t length, int align);
    void   incPoolSize();
public:
    char *          pool;

    N2StringPool();
    N2StringPool(size_t incbase);
    ~N2StringPool();
    size_t addStr(const char* str);
    size_t addUtf16Str(const unsigned short* str);
    size_t addUtf32Str(const unsigned int* str);
    const char * getStr(size_t offset);
    const unsigned short * getUtf16Str(size_t offset);
    const unsigned int * getUtf32Str(size_t offset);

    size_t getPoolSize();
    size_t getUsedSize();
    void clearPool();
    void clearAndFreePool();
};

class N2PoolString
{
protected:
    static N2StringPool *   pool;
public:
    size_t                  length;
    union {
        size_t              offset;
        char                str[8];
    }                       data;
    N2PoolString();
    N2PoolString(const char* str);
    static void setStringPool(N2StringPool * stringpool);
    size_t getLength();
    const char * c_str() const;
    const char * setstr(const char* str);
};


struct TN2DataPoolBlock
{
    unsigned char *     data;
    size_t              blocksize;
    size_t              used;
};

class N2DataPool
{
private:
    void increaseBlockNumber();
public:
    n2u64               datasize;               // the total size of data be write
    TN2DataPoolBlock  * blocks;
    size_t              minBlockSize;
    size_t              block_alloc;            // the number of allocated blocks
    size_t              curblockid;             // the number of used blocks
    size_t              block_base;

    N2DataPool(size_t minSize, size_t blockbase);
    ~N2DataPool();
    void addBinaryData(unsigned char * data, size_t size);
    n2u64 getTotalDataSize();
    void clearAllData();
};



#endif //











